<?php

/**
 * This is the model class for table "sh_cook".
 *
 * The followings are the available columns in table 'sh_cook':
 * @property integer $id
 * @property integer $cateogory_id
 * @property string $name
 * @property string $image
 * @property integer $time_cook
 * @property integer $diff_cook
 * @property integer $price
 * @property string $short_description
 * @property string $materials
 * @property string $step
 * @property integer $customer_id
 */
class Cook extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Cook the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'sh_cook';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('cateogory_id, time_cook, diff_cook, price, customer_id', 'numerical', 'integerOnly'=>true),
			array('name, image', 'length', 'max'=>250),
			array('short_description, materials, step', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, cateogory_id, name, image, time_cook, diff_cook, price, short_description, materials, step, customer_id, status', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'cateogory_id' => 'Danh mục',
			'name' => 'Tên món ăn',
			'image' => 'Image',
			'time_cook' => 'Thời gian nấu ăn',
			'diff_cook' => 'Độ phức tạp',
			'price' => 'Giá',
			'short_description' => 'Mô tả ngắn',
			'materials' => 'Dinh dưỡng',
			'step' => 'Bước thực hiện',
			'customer_id' => 'Người gửi',
                        'status' => 'Trạng thái',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('cateogory_id',$this->cateogory_id);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('image',$this->image,true);
		$criteria->compare('time_cook',$this->time_cook);
		$criteria->compare('diff_cook',$this->diff_cook);
		$criteria->compare('price',$this->price);
		$criteria->compare('short_description',$this->short_description,true);
		$criteria->compare('materials',$this->materials,true);
		$criteria->compare('step',$this->step,true);
		$criteria->compare('customer_id',$this->customer_id);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
        
        public static function getTimeCook(){
            return array('1'=>'Dưới 15 phút','2'=>'Từ 15 phút đến 30 phút','3'=>'Từ 30 phút đến 1 tiếng','4'=>'Trên 1 tiếng');
        }
}